package com.chen.service.impl;

import com.chen.domain.Student;
import com.chen.mapper.StudentMapper;
import com.chen.service.StudentService;
import com.chen.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageBean<Student> queryPage(Map<String, Object> paramMap) {
       PageBean<Student> pageBean=new PageBean<>((Integer)paramMap.get("pageno"),(Integer)paramMap.get("pagesize"));

       Integer startIndex=pageBean.getStartIndex();
       paramMap.put("startIndex",startIndex);
       List<Student> datas=studentMapper.queryList(paramMap);
       pageBean.setDatas(datas);

       Integer totalsize=studentMapper.queryCount(paramMap);
       pageBean.setTotalsize(totalsize);
       return pageBean;
    }

    @Override
    public Integer deleteStudent(List<Integer> ids) {
        return studentMapper.deleteStudent(ids);
    }

    @Override
    public Integer addStudent(Student student) {
        return studentMapper.addStudent(student);
    }

    @Override
    public Student findById(Integer sid) {
        return studentMapper.findById(sid);
    }

    @Override
    public Integer editStudent(Student student) {
        return studentMapper.editStudent(student);
    }

    @Override
    public Student findByStudent(Student student) {
        return studentMapper.findByStudent(student);
    }

    @Override
    public Integer editPswByStudent(Student student) {
        return studentMapper.editPswByStudent(student);
    }

    @Override
    public Integer findByName(String name) {
        return studentMapper.findByName(name);
    }

    @Override
    public Boolean isStudentByClazzId(Integer id) {
        List<Student> studentByClazzId = studentMapper.isStudentByClazzId(id);
        if(studentByClazzId.isEmpty()){
            return true;
        }else{
            return false;
        }
    }
}
